* Data
*use "Reelection all data Jun 1 2015.dta", clear

* Recodes
encode DepVar, gen(depvar)
recode depvar (2 3=0) (1=1), gen(expansion)
recode depvar (1 2=0) (3=1), gen(restriction)
label define expansionLBL 0 "No relaxation" 1 "Expansion"
label values expansion expansionLBL
*replace popularity = popularity/100
*replace shareseats = shareseats/100
label variable shareseats "Share of Seats"
label variable popularity "Approval Rate"
label variable abspolicymove "Policy Move"
tab Ideologyperception, gen(ideology)
rename ideology1 leftwing
rename ideology2 moderate
rename ideology3 rightwing
recode Ideologyperception (-1=1) (0=0) (1=2)
label define IdeologyLBL 1 "Ideology is -1" 2 "Ideology is +1"
label values Ideologyperception IdeologyLBL
label define rulingpartyvetoLBL 0 "No ruling party veto" 1 "Ruling party veto"
label values rulingpartyveto rulingpartyvetoLBL

* Bolivia case
gen Bolivia=0
replace Bolivia=1 if countryyear=="Bolivia 2015 (Morales)"
*drop if Bolivia==1

even pauze hier

* Descriptives
bys Bolivia: sum shareseats popularity rulingpartyveto i.Ideologyperception policymove abspolicymove

* Graphs
graph bar (mean) shareseats, blabel(bar, format(%9.2f)) over(expansion) ytitle("") title(Share of seats) scheme(lean1) name(graph1, replace)
window manage close graph
graph bar (mean) popularity, blabel(bar, format(%9.2f)) over(expansion) ytitle("") title(Popularity) scheme(lean1) name(graph2, replace)
window manage close graph
graph bar (mean) abspolicymove, blabel(bar, format(%9.2f)) over(expansion) ytitle("") title(Policy move (abs)) scheme(lean1) name(graph3, replace)
window manage close graph
graph bar (mean) leftwing, blabel(bar, format(%9.2f)) over(expansion) ytitle("") title(Statist ideology) scheme(lean1) name(graph4, replace)
window manage close graph
graph bar (mean) moderate, blabel(bar, format(%9.2f)) over(expansion) ytitle("") title(Moderate ideology) scheme(lean1) name(graph5, replace)
window manage close graph
graph bar (mean) rightwing, blabel(bar, format(%9.2f))  over(expansion) ytitle("") title(Market-oriented ideology) scheme(lean1) name(graph6, replace)
window manage close graph
graph bar (mean) rulingpartyveto, blabel(bar, format(%9.2f))  over(expansion) ytitle("")  title(Ruling party veto) scheme(lean1) name(graph7, replace)
window manage close graph
graph combine graph1 graph2 graph3 graph4 graph5 graph6 graph7, scheme(lean1)

mean shareseats, over(expansion)
mean popularity, over(expansion)
mean abspolicymove, over(expansion)

* Regression - logistic
*replace popularity = popularity*100
*replace shareseats = shareseats*100

logit expansion shareseats, or 
estimates store model1

logit expansion popularity, or
estimates store model2

logit expansion rulingpartyveto, or
estimates store model3

logit expansion i.Ideologyperception, or
estimates store model4

logit expansion policymove, or
estimates store model5

logit expansion abspolicymove, or
estimates store model6

logit expansion c.popularity##c.rulingpartyveto, or
estimates store model7

logit expansion shareseats popularity rulingpartyveto i.Ideologyperception policymove abspolicymove c.popularity#c.rulingpartyveto, or
estimates store model8

estout model1 model2 model3 model4 model5 model6 model7 model8, cells(b(star fmt(%9.3f)) se(par)) stats(r2_p N, fmt(%9.3f %9.0g) labels(R-squared))      ///
	legend label collabels(none) varlabels(_cons Constant) eform

* Interaction
logit expansion c.popularity##c.rulingpartyveto, or
margins, at(popularity=(0(10)100) rulingpartyveto=(0 1))
marginsplot, scheme(lean1)

* Regression - multinomial
mlogit depvar shareseats, base(1) rrr
estimates store model1

mlogit depvar popularity, base(1) rrr
estimates store model2

mlogit depvar rulingpartyveto, base(1) rrr 
estimates store model3

mlogit depvar i.Ideologyperception, base(1) rrr
estimates store model4

mlogit depvar policymove, base(1) rrr
estimates store model5

mlogit depvar abspolicymove, base(1) rrr
estimates store model6

mlogit depvar c.popularity##c.rulingpartyveto, base(1) rrr
estimates store model7

*mlogit depvar shareseats popularity rulingpartyveto i.Ideologyperception policymove abspolicymove, base(1) rrr
*estimates store model8

estout model1 model2 model3 model4 model5 model6 model7 , cells(b(star fmt(%9.3f)) se(par)) stats(r2_p N, fmt(%9.3f %9.0g) labels(R-squared))      ///
	legend label collabels(none) varlabels(_cons Constant) eform
